﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Student_management
{
    public partial class frmTraCuuHS : Form
    {
        Connection db = new Connection();
        string sql = "Select A.MaHS as 'Mã', A.HoTen as 'Họ và tên', A.MaLop as 'Lớp', A.GioiTinh as 'Giới Tính', A.NgaySinh as 'Ngày sinh', A.DiaChi as 'Địa chỉ', A.Email, A.SDT, B.HK1, B.HK2  from HocSinh A LEFT OUTER JOIN Diem B on A.MaHS = B.MaHS";
        public frmTraCuuHS()
        {
            InitializeComponent();
        }

        private void frmTraCuuHS_Load(object sender, EventArgs e)
        {
            this.Dock = DockStyle.Fill;
            grdt.DataSource = addstt(db.getDS(sql));
            grdt.Columns["STT"].DisplayIndex = 0;
        }

        DataTable addstt(DataTable a)
        {
            a.Columns.Add("STT");
            for (int i = 0; i < a.Rows.Count; i++)
                a.Rows[i]["STT"] = i + 1;
            return a;
        }
        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            DataTable HS = new DataTable();
            if (rb2.Checked)
                HS = addstt(db.getDS(sql + " Where A.MaHS LIKE '%" + textBox1.Text + "%'"));
            if (rb3.Checked)
                HS = addstt(db.getDS(sql + " Where A.HoTen LIKE N'%" + textBox1.Text + "%'"));
            if (rb4.Checked)
                HS = addstt(db.getDS(sql + " Where A.Malop LIKE N'%" + textBox1.Text + "%'"));
            if (rb5.Checked)
                HS = addstt(db.getDS(sql + " Where A.DiaChi LIKE N'%" + textBox1.Text + "%'"));
            if (rb1.Checked)
                HS = addstt(db.getDS(sql + " Where (A.MaHS LIKE '%" + textBox1.Text + "%' or A.HoTen LIKE N'%" + textBox1.Text + "%' or A.MaLop LIKE N'%" + textBox1.Text + "%' or A.DiaChi LIKE N'%" + textBox1.Text + "%')"));
            grdt.DataSource = HS;
        }
    }
}
